/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.octgame.octantis.flight;

import org.lwjgl.util.Point;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Line;
import org.newdawn.slick.geom.ShapeRenderer;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
import org.octgame.resources.twl.BasicTWLGameState;
import org.octgame.utilities.geometry.Geometry;

/**
 *
 * @author Hempa
 */
public class FlightState extends BasicTWLGameState {

    private int stateID = -1;
    private Input i;

    Vector2f center;
    Vector2f click;
    Vector2f rClick;

    Line l1;
    Line l2;


    public FlightState(int id) {
        stateID = id;
    }

    @Override
    public int getID() {
        return this.stateID;
    }

    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        System.out.println("360 deg in rad: " + Math.toRadians(359));
        System.out.println("  0 deg in rad: " + Math.toRadians(0));
        System.out.println("2 PI          : " + 2*(Math.PI));
        i = gc.getInput();
        center = new Vector2f(gc.getWidth()/2, gc.getHeight()/2);
        click = new Vector2f(0,0);
        rClick = new Vector2f(0,0);
        

        l1 = new Line(center,click);
        l2 = new Line(center,rClick);

    }

    

    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        g.setColor(Color.yellow);
        ShapeRenderer.draw(l1);
        g.drawString(l1.toString(), 0, gc.getHeight()-20);
        g.setColor(Color.red);
        ShapeRenderer.draw(l2);
        g.drawString(l2.toString(), 0, gc.getHeight()-40);


        g.setColor(Color.green);
        
        

        
        g.setColor(Color.blue);

        // Draw an arc between the lines here.
        
    }

    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        if (i.isMouseButtonDown(i.MOUSE_LEFT_BUTTON))
        {
            click.x = i.getMouseX();
            click.y = i.getMouseY();

            l1.set(center, click);
        } else if (i.isMouseButtonDown(i.MOUSE_RIGHT_BUTTON))
        {
            rClick.x = i.getMouseX();
            rClick.y = i.getMouseY();

            l2.set(center, rClick);

        } else if (i.isMouseButtonDown(i.MOUSE_MIDDLE_BUTTON))
        {
            center.x = i.getMouseX();
            center.y = i.getMouseY();

            l1.set(center, click);
            l2.set(center, rClick);
        }
    }
}
